package utils;
import java.io.Serializable;
import java.util.List;

import tables.TransportTable;
import app.WebApp;
import dao.BindingDao;
import dao.RouteDao;
import dao.TransportDao;
import entity.Binding;
import entity.Route;
import entity.Transport;

public class Utils {
	final static RouteDao rDao = new RouteDao(WebApp.DATA_XML_FOLDER);
	final static TransportDao tDao = new TransportDao(WebApp.DATA_XML_FOLDER);
	final static BindingDao bDao = new BindingDao(WebApp.DATA_XML_FOLDER);
	final List<Route> allRoute = rDao.getAll();
	final static List<Binding> allBind = bDao.getAll();
	public static String getAllAutobusByRoute(Route route) {
		List<Transport> list= tDao.getAllAutobus();
		String allTime = "";
		for (Transport c : list) {
			for(Binding b: allBind)
				if(route.getId().equals(b.getBind())){
					if(b.getRoute().equals(c.getRoute())){
						allTime+=c.getTime()+"; ";
					}
			}
		}
		return allTime;
	}
	public static String getAllTrolleybusByRoute(Route route) {
		List<Transport> list= tDao.getAllTrolleybus();
		String allTime = "";
		for (Transport c : list) {
			for(Binding b: allBind)
				if(route.getId().equals(b.getBind())){
					if(b.getRoute().equals(c.getRoute())){
						allTime+=c.getTime()+"; ";
					}
			}
		}
		return allTime;
	}
	public static String getAllTrumByRoute(Route route) {
		List<Transport> list= tDao.getAllTrum();
		String allTime = "";
		for (Transport c : list) {
			for(Binding b: allBind)
				if(route.getId().equals(b.getBind())){
					if(b.getRoute().equals(c.getRoute())){
						allTime+=c.getTime()+"; ";
					}
			}
		}
		return allTime;
	}
	/*public static void updateRoute(Route oldRoute, Route newRoute){
		List<Transport> list = tDao.getAll();
		for( Binding b : allBind) {
			if(oldRoute.getId().equals(b.getBind())){
			for(Transport t : list){
				if(t.getRoute().equals(b.getRoute())){
					Transport tr = new Transport();
					tr.setRoute(newRoute.get);
				}
			}
		}
	}*/
	public static void delete(Route route) {
		final List<Transport> allTrans = tDao.getAll();
		for( Binding b : allBind){
			if(route.getId().equals(b.getBind())){
				for(Transport t: allTrans){
				tDao.deleteByRoute(b.getRoute());
				}
			}
		}
		rDao.delete(route.getId());
		bDao.delete(route.getId());
		
		
	}
}
